package oss.ngocminh.fw.forum;

import java.io.IOException;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;

import org.apache.http.client.HttpClient;

import oss.ngocminh.fw.data.Post;
import oss.ngocminh.fw.data.Thread;

public class MockForum implements ForumAdapter {

	private int count = 1;
	private List<Post> postList1;
	private List<Post> postList2;
	private List<Post> allPosts = new ArrayList<Post>();
	private List<Post> newPosts = new LinkedList<Post>();
	
	public MockForum() {
		postList1 = new ArrayList<Post>();
		postList1.add(new Post("1", "minh", new Date(), "abc", "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed"));
		postList1.add(new Post("2", "hung", new Date(), "def", "do eiusmod tempor incididunt ut labore"));
		postList1.add(new Post("3", "long", new Date(), "ghij", "et dolore magna aliqua. Ut enim ad minim veniam"));
		postList1.add(new Post("4", "hung", new Date(), "klm", "quis nostrud exercitation ullamco laboris nisi ut aliquip"));
		postList1.add(new Post("5", "long", new Date(), "nop", "ex ea commodo consequat. Duis aute irure dolor in reprehenderit"));
		postList2 = new ArrayList<Post>();
		postList2.add(new Post("6", "minh", new Date(), "qrs", "in voluptate velit esse cillum dolore "));
		postList2.add(new Post("7", "hung", new Date(), "tuv", "eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident"));
		postList2.add(new Post("8", "minh", new Date(), "xyz", "sunt in culpa qui officia deserunt mollit anim id est laborum"));
	}
	
	@Override
	public HttpClient getHttpClient() {
		throw new UnsupportedOperationException();
	}

	@Override
	public boolean login(String userName, String password, String baseUrl) throws IOException {
		return true;
	}

	@Override
	public List<Post> getPostsOfPage(Thread thread, int page)
			throws IOException, ParseException {
		return Collections.emptyList();
	}

	@Override
	public List<Post> getNewPosts(Thread thread, Date fromDate)
			throws IOException, ParseException {
		if (count == 1) {
			count++;
			allPosts.addAll(postList1);
			return postList1;
		}
		if (count == 2) {
			count++;
			allPosts.addAll(postList2);
			return postList2;
		}
		ArrayList<Post> posts = new ArrayList<Post>(newPosts);
		allPosts.addAll(newPosts);
		newPosts.clear();
		return posts;
	}

	@Override
	public List<Post> getAllPosts(Thread thread) {
		return allPosts;	
	}

	@Override
	public boolean submitPost(Post post, Thread thread) {
		newPosts.add(post);
		return true;
	}

	@Override
	public List<Post> getPostsFromPage(Thread thread, int page)
			throws IOException, ParseException {
		return null;
	}

	@Override
	public void getPostsOfPage(Thread thread, int page,
			PostLoadingCallback callback) throws IOException, ParseException {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void getPostsFromPage(Thread thread, int page,
			PostLoadingCallback callback) throws IOException, ParseException {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void getNewPosts(Thread thread, Date fromDate,
			PostLoadingCallback callback) throws IOException, ParseException {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void getAllPosts(Thread thread, PostLoadingCallback callback)
			throws IOException, ParseException {
		// TODO Auto-generated method stub
		
	}

}
